{% extends 'default/base.html' %}
{% block content %}
{% load pagination_tags %}
{% load business_tag %}
<style>
    .test_width{ width:130px; }
</style>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="ibox float-e-margins">
            <div id="edit_result">
                <div class="ibox-title">
                    <h5> 主机详细信息列表 <span style="color:red">总共有:{{server_list_count}}台  真实机:{{ physics }}  虚拟机: {{ vms }}台</span></h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user"></ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form id="asset_form">
                        {% csrf_token %}
                        <div class="col-sm-1 test_width" style="padding-left: 0px">
                            <label>
                                <select name="change_idc" class="form-control m-b" onchange="change_info()">
                                    <option value="">所有机房</option>
                                    {% for i in idcs %}
                                        <option value="{{i.name}}"> {{ i }}</option>
                                    {% endfor %}
                                </select>
                            </label>
                        </div>
                        <div class="col-sm-1 test_width">
                            <label>
                                <select name="change_business" class="form-control m-b" onchange="change_info()">
                                    <option value="all">所有项目</option>
                                    {% for i in server_type %}
                                    <option value="{{i.service_name}}"> {{ i }}</option>
                                    {% endfor %}
                                </select>
                            </label>
                        </div>
                        <div class="col-sm-1 test_width">
                            <label>
                                <select name="change_service" class="form-control m-b" onchange="change_info()">
                                    <option value="all">所有服务</option>
                                    {% for i in services %}
                                    <option value="{{i.name}}"> {{ i }}</option>
                                    {% endfor %}
                                </select>
                            </label>
                        </div>
                         <div class="col-sm-1 test_width">
                             <label>
                                 <select name="change_status" class="form-control m-b" onchange="change_info()">
                                     <option value="">所有状态</option>
                                     {% for i in server_status %}
                                     <option value="{{ i.0 }}"> {{ i.1 }}</option>
                                     {% endfor %}
                                 </select>
                             </label>
                         </div>
                        <div class="col-sm-1 test_width">
                            <label>
                                <select name="change_brand" class="form-control m-b" onchange="change_info()">
                                    <option value="">所有型号</option>
                                    {% for i in brands %}
                                    <option value="{{ i.0 }}"> {{ i.1 }}</option>
                                    {% endfor %}
                                </select>
                            </label>
                        </div>
                        <div class="col-sm-1 test_width">
                            <label>
                                <select name="change_type" class="form-control m-b" onchange="change_info()">
                                    <option value="">所有类型</option>
                                    <option value="1">物理机</option>
                                    <option value="0">虚拟机</option>
                                </select>
                            </label>
                        </div>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" class="form-control m-b" id="search_input" name="keyword" placeholder="Search">
                                <input type="text" style="display: none">
                                <div class="input-group-btn">
                                    <button type="button" href="/assets/change_info_ajax/?search=true" name="search" class="btn btn-xm btn-primary search_btn" onclick="return false">
                                        搜索
                                    </button>
{#                                    <button type="button" href="/assets/change_info_ajax/?_search=true" name="_search" class="btn btn-xm btn-success search_btn_pdf" onclick="return false">#}
{#                                        导出#}
{#                                    </button>#}
                                    <div class="btn-group" role="group">
                                        <button type="button" class="btn btn-xm btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                          导出
                                          <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                          <li><a href="/assets/change_info_ajax/?_search=true&name=pdf" class="search_btn_pdf" name="search" onclick="return false" >导出pdf</a></li>
                                          <li><a href="/assets/change_info_ajax/?_search=true&name=excel" class="search_btn_pdf" name="search" onclick="return false" >导出excel</a></li>
                                        </ul>
                                      </div>

                                </div>
                            </div>
                        </div>
                        <div id="download"></div>
                        <div id="replace">
                            <table id="host_info" class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th class="text-center"><input type="checkbox" id="select_all" onclick="check_all('asset_form')"></th>
                                        <th class="text-center"> IP </th>
                                        <th class="text-center"> 主机名 </th>
                                        <th class="text-center"> IDC </th>
                                        <th class="text-center"> 资产编号 </th>
                                        <th class="text-center"> 品牌 </th>
                                        <th class="text-center"> 配置 </th>
                                        <th class="text-center"> 项目 </th>
                                        <th class="text-center"> 服务 </th>
                                        <th class="text-center"> 状态 </th>
                                        <th class="text-center"> 操作 </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for i in contacts.object_list %}
                                        <tr class="gradeX">

                                            <td class="text-center"><input type="checkbox" name="selected" value="{{ i.uuid }}"></td>
                                            {% if i.eth1 %}
                                                <td class="text-center"> <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="select_node" ><i class="fa fa-linux" style="color:#080506"></i> {{ i.eth1 }} </a></td>
                                            {% elif i.eth2 %}
                                                <td class="text-center"> <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="select_node" ><i class="fa fa-linux" style="color:#080506"></i> {{ i.eth2 }} </a></td>
                                            {% else %}
                                                <td class="text-center"> <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="select_node" ><i class="fa fa-linux" style="color:#080506"></i> {{ i.eth1 }} </a></td>
                                            {% endif %}
{#                                            <td class="text-center"> <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="select_node" ><i class="fa fa-linux" style="color:#080506"></i> {{ i.eth1 }} </a></td>#}
                                            <td class="text-center"> {{ i.node_name }} </td>
                                            <td class="text-center"> {{ i.idc.name }} </td>
                                            <td class="text-center"> {{ i.number }} </td>
                                            <td class="text-center"> {{ i.brand }} </td>
                                            <td class="text-center"> {{ i.cpu }} <span class="text-success">|</span> {{ i.memory }} <span class="text-success">|</span> {{ i.hard_disk }}</td>
                                            <td class="text-center">
                                                {% for s in i.uuid|business_list %}
                                                     <a href="/assets/server/server_type/?service_name={{ s }}" class="btn btn-info btn-xs">{{ s }}</a>
                                                {% endfor %}
                                            </td>
                                            <td class="text-center">
                                                {{ i.service.all|group_str2 }}
                                            </td>
                                            <td class="text-center">
                                                <div class="btn-group tooltip-demo" data-toggle="buttons">
                                                    {% if i.status == 0 %}
                                                        <span class="glyphicon glyphicon-remove"  data-toggle="tooltip" data-placement="bottom" title="未安装系统" aria-hidden="true" style="color: #ff6846"></span>
                                                    {% elif i.status == 1 %}
                                                        <span class="glyphicon glyphicon-ok" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="已安装系统" style="color:#2ad49e"></span>
                                                    {% elif i.status == 3 %}
                                                        <span class="fa fa-trash-o text-danger"  type="button" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="报废"></span>
                                                    {% else %}
                                                    <span class="glyphicon glyphicon-saved" aria-hidden="true" data-toggle="tooltip" data-placement="bottom" title="安装系统中..." style="color:#2d98d4"></span>
                                                    {% endif %}
                                                </div>
                                            </td>
                                            <td class="text-center">
{#                                                <div class="tooltip-demo">#}
{#                                                {% if request.user.is_superuser or request.session.fun_auth.edit_host %}#}
{#                                                <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="btn btn-xs btn-primary">详情</a>#}
{#                                                <a href="/assets/host_edit/?uuid={{ i.uuid }}" class="btn btn-xs btn-info">修改</a>#}
{#                                                {% endif %}#}
{#                                                {% if request.user.is_superuser or request.session.fun_auth.delete_host %}#}
{#                                                <a href="/assets/host_del/?uuid={{ i.uuid }}" class="btn btn-xs btn-danger node-edit" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-trash-o"></i></a>#}
{#                                                {% endif %}#}
{#                                                {% if i.status == 1 and request.user.is_superuser or request.session.fun_auth.update_host %}#}
{#                                                <a href="/assets/update_id/{{ i.id }}/" class="btn btn-xs btn-success" data-toggle="tooltip" data-placement="bottom" title="自动上报硬件信息"><i class="fa fa-recycle">更新</i></a>#}
{#                                                {% elif request.user.is_superuser or request.session.fun_auth.update_host %}#}
{#                                                    <a href="/assets/update_id/{{ i.id }}/" class="btn btn-xs btn-success disabled" data-toggle="tooltip" data-placement="bottom" title="自动上报硬件信息"><i class="fa fa-recycle">更新</i></a>#}
{#                                                {% else %}#}
{#                                                {% endif %}#}
{#                                                {% if request.user.is_superuser or request.session.fun_auth.setup_system %}#}
{#                                                    <a href="/assets/server/restart/{{ i.id }}/" class="btn btn-xs btn-danger voilet_restart" data-toggle="tooltip" data-placement="bottom" title="重装系统"><i class="fa fa-desktop">装机</i></a>#}
{#                                                {% endif %}#}
{#                                                </div>#}
                                                <a href="/assets/host_detail/?uuid={{ i.uuid }}" class="btn btn-xs btn-primary" data-toggle="tooltip" data-placement="bottom" title="详情">详情</a>
                                                <a href="/assets/host_edit/?uuid={{ i.uuid }}" class="btn btn-xs btn-info" data-toggle="tooltip" data-placement="bottom" title="修改">修改</a>
                                                <a href="/assets/host_del/?uuid={{ i.uuid }}" class="btn btn-xs btn-danger node-edit" data-toggle="tooltip" data-placement="bottom" title="删除">删除</a>
                                                <a href="/assets/host_update/?uuid={{ i.uuid }}" class="btn btn-xs btn-success" data-toggle="tooltip" data-placement="bottom" title="自动上报硬件信息">更新</a>
                                                <a href="/assets/zabbix_host/?uuid={{ i.uuid }}" class="btn btn-xs btn-default" data-toggle="tooltip" data-placement="bottom" title="监控信息">监控</a>
                                                <a href="/assets/server/restart/{{ i.uuid }}/" class="btn btn-xs btn-warning voilet_restart" data-toggle="tooltip" data-placement="bottom" title="重装系统">装机</a>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>

                            <div class="row">
                                <div class="col-sm-6">
                                    <div id="host_list">
                                        <button type="button" class="btn btn-danger" id="host_del">批量删除</button>
                                        <a value="/assets/host_edit_batch/" type="button" class="btn btn-warning iframe" id="host_edit">批量修改</a>
                                        <a href="/assets/host_add/" type="button" class="btn btn-info">添加主机</a>
                                    </div>
                                </div>
                                {% if search %}
                                    {% include 'assets/paginator_search.html' %}
                                {% else %}
                                    {% include 'assets/paginator.html' %}
                                {% endif %}
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $('#host_del').click(function () {
            var ids = getids();
            if (ids == ''){
                alert("请至少选择一行!");
                return false;
            }
            if (confirm("确定删除")) {
                $.ajax({
                    type: "post",
                    data: {ids: ids},
                    url: "/assets/host_del_batch/",
                    success: function () {
                        window.open("/assets/host_list/", "_self");
                    }
                });
            }
        });


        $(".iframe").on('click', function(){
            var ids = getids();
            if (ids == ''){
                alert("请至少选择一行!");
                return false;
            }
            var url= $(this).attr("value") + '?uuid=' + ids;
                index = $.layer({
                    type: 2,
                    title: '风行网自动化运维平台-批量修改主机',
                    maxmin: true,
                    shift: 'top',
                    border: [2, 0.3, '#1AB394'],
                    shade: [0.5, '#000000'],
                    shadeClose: true,
                    area : ['800px' , '600px'],
                    iframe: {src: url},
                    close: function(){
                        location.replace(location.href);
                    }
                });
        });
    });

    $("#search_input").keydown(function(e){
        if(e.keyCode==13){
            change_info()
            }
    });
    $('.search_btn').unbind('click').bind('click',function(){
        var url= $(this).attr("href");
        $.ajax({
            type: "GET",
            url: url,
            data: $("#asset_form").serialize(),
            success: function (data) {
                $("#replace").html(data);
            }
        });
    });
    $('.search_btn_pdf').unbind('click').bind('click',function(){
        var url= $(this).attr("href");
        $.ajax({
            type: "GET",
            url: url,
            data: $("#asset_form").serialize(),
            success: function (data) {
                $("#download").html(data);
            }
        });
    });
    function change_info(){
        // var data = $("#asset_form").serialize();
        // location.href = "/assets/change_info_ajax/?" + data;
        $.ajax({
            type: "GET",
            url: "/assets/change_info_ajax/",
            data: $("#asset_form").serialize(),
            success: function (data) {
                $("#replace").html(data);
            }
        });
    }
</script>

{% endblock  %}

